package com.wisecoach.gatewayplus.event;

import com.wisecoach.util.Assert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 区块事件源注册器
 * {@code @author:} wisecoach
 * {@code @date:} 2023/6/14 下午10:14
 * {@code @version:} 1.0.0
 */

public class FilteredBlockSourceRegistry {

    private final Map<String, FilteredBlockSource> sources = new ConcurrentHashMap<>();

    public FilteredBlockSource getSource(String channelName) {
        FilteredBlockSource source = sources.get(channelName);
        if (source == null) {
            throw new EventException("暂时没有注册该channel的区块源");
        }
        return source;
    }

    public void register(String channelName, FilteredBlockSource source) {
        Assert.notNull(channelName, "channel不可为空");
        Assert.notNull(source, "source不可为空");
        sources.put(channelName, source);
    }


}
